<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 *  昵称池
 */
class NickNamePool extends Model
{
    protected $table = 'nick_name_pool';
    protected $fillable = ['gender', 'type', 'content', 'flag'];

    /**
     * 选择昵称
     */
    static function pickNickName($gender = 0)
    {
        $genders = [-1, $gender];

        $where = ['flag' => 1, 'type' => 'prefix'];
        $pre = self::where($where)->whereIn('gender', $genders)->inRandomOrder()->first();

        $where = ['flag' => 1, 'type' => 'suffix'];
        $suf = self::where($where)->whereIn('gender', $genders)->inRandomOrder()->first();

        return ($pre ? $pre->content : '可爱的') . ($suf ? $suf->content : '大强');
    }
}
